import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
import Layout from '@/layout'
export const constantRoutes = [{
		path: '/redirect',
		component: Layout,
		hidden: true,
	},
	{
		path: '/login',
		component: () =>
			import('@/views/login/index'),
		hidden: true
	},
	{
		path: '/auth-redirect',
		component: () =>
			import('@/views/login/auth-redirect'),
		hidden: true
	},
	{
		path: '/4`04',
		component: () =>
			import('@/views/error-page/404'),
		hidden: true
	},
	{
		path: '/401',
		component: () =>
			import('@/views/error-page/401'),
		hidden: true
	},
	{
		path: '/',
		component: Layout,
		redirect: '/communityInfo/build',
		children: [{
				path: 'dashboard',
				component: () =>
					import('@/views/dashboard/index'),
				name: '首页',
				meta: {
					title: '首页',
					icon: 'el-icon-s-home',
					affix: true
				}
			},
			//不连接后端时的默认路由
			{
				path: 'communityInfo/list',
				component: () =>
					import('@/views/communityInfo/list/index'),
				name: 'Role',
				meta: {
					title: '基础信息',
					icon: 'el-icon-s-home',
					affix: true
				},
				children: [{
					path: '/communityInfo/build',
					component: () =>
						import('@/views/communityInfo/pages/build/index.vue'),
					name: 'build',
					meta: {
						title: '基础信息-楼宇列表',
					}
				}, {
					path: '/communityInfo/person',
					component: () =>
						import('@/views/communityInfo/pages/person/index.vue'),
					name: 'person',
					meta: {
						title: '基础信息-人员列表',
					}
				}, {
					path: '/communityInfo/shebei',
					component: () =>
						import('@/views/communityInfo/pages/shebei/index.vue'),
					name: 'shebei',
					meta: {
						title: '基础信息-设备列表',
					}
				}]
			},
			{
				path: 'shops/list',
				component: () =>
					import('@/views/shops/list/index'),
				name: 'Role',
				meta: {
					title: '商铺管理',
					icon: 'el-icon-s-home',
					affix: true
				},
				children: [{
					path: '/shops/order',
					component: () =>
						import('@/views/shops/pages/order/index.vue'),
					name: 'order',
					meta: {
						title: '商铺管理-订单管理',
					}
				}, {
					path: '/shops/shopList',
					component: () =>
						import('@/views/shops/pages/shopList/index.vue'),
					name: 'shopList',
					meta: {
						title: '商铺管理-商铺列表',
					}
				}]
			},
			{
				path: 'complaints/list',
				component: () =>
					import('@/views/complaints/list/index'),
				name: 'Role',
				meta: {
					title: '投诉报修',
					icon: 'el-icon-s-home',
					affix: true
				},
				children: [{
					path: '/complaints/tousu',
					component: () =>
						import('@/views/complaints/pages/tousu/index.vue'),
					name: 'tousu',
					meta: {
						title: '投诉保修-投诉列表',
					}
				}, {
					path: '/complaints/baoxiu',
					component: () =>
						import('@/views/complaints/pages/baoxiu/index.vue'),
					name: 'baoxiu',
					meta: {
						title: '投诉保修-报修列表',
					}
				}]
			},
			{
				path: 'video/list',
				component: () =>
					import('@/views/video/list/index'),
				name: 'Role',
				meta: {
					title: '监控管理',
					icon: 'el-icon-s-home',
					affix: true
				},
				children: [{
					path: '/video/videoList',
					component: () =>
						import('@/views/video/pages/videoList/index.vue'),
					name: 'videoList',
					meta: {
						title: '监控管理-监控列表',
					}
				}]
			},
			{
				path: 'message/list',
				component: () =>
					import('@/views/message/list/index'),
				name: 'Role',
				meta: {
					title: '公告管理',
					icon: 'el-icon-s-home',
					affix: true
				},
				children: [{
					path: '/message/gonggao',
					component: () =>
						import('@/views/message/pages/gonggao/index.vue'),
					name: 'gonggao',
					meta: {
						title: '公告管理-公告列表',
					}
				}]
			},
			{
				path: 'advertise/list',
				component: () =>
					import('@/views/advertise/list/index'),
				name: 'Role',
				meta: {
					title: '广告位管理',
					icon: 'el-icon-s-home',
					affix: true
				},
				children: [{
					path: '/advertise/adList',
					component: () =>
						import('@/views/advertise/pages/adList/index.vue'),
					name: 'adList',
					meta: {
						title: '广告列表',
					}
				}, {
					path: '/advertise/flagList',
					component: () =>
						import('@/views/advertise/pages/flagList/index.vue'),
					name: 'flagList',
					meta: {
						title: '广告位列表',
					}
				}]
			},
			{
				path: 'rental/list',
				component: () =>
					import('@/views/rental/list/index'),
				name: 'Role',
				meta: {
					title: '租售信息',
					icon: 'el-icon-s-home',
					affix: true
				},
				children: [{
					path: '/rental/buildList',
					component: () =>
						import('@/views/rental/pages/buildList/index.vue'),
					name: 'buildList',
					meta: {
						title: '租售信息-房屋租售',
					}
				}, {
					path: '/rental/carList',
					component: () =>
						import('@/views/rental/pages/carList/index.vue'),
					name: 'carList',
					meta: {
						title: '租售信息-车辆租售',
					}
				}]
			},
			{
				path: 'work/list',
				component: () =>
					import('@/views/work/list/index'),
				name: 'Role',
				meta: {
					title: '工作招聘',
					icon: 'el-icon-s-home',
					affix: true
				},
				children: [{
					path: '/work/workerList',
					component: () =>
						import('@/views/work/pages/workerList/index.vue'),
					name: 'workerList',
					meta: {
						title: '工作招聘-岗位列表',
					}
				}, {
					path: '/work/workList',
					component: () =>
						import('@/views/work/pages/workList/index.vue'),
					name: 'workList',
					meta: {
						title: '工作招聘-求职者列表',
					}
				}]
			},
		]
	},
]

export const asyncRoutes = [{
	path: '*',
	redirect: '/404',
	hidden: true
}]

const createRouter = () => new Router({
	scrollBehavior: () => ({
		y: 0
	}),
	routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
	const newRouter = createRouter()
	router.matcher = newRouter.matcher // reset router
}

export default router
